


let oddCrossGrid = require('./oddCrossGrid');
let evenCrossGrid = require('./evenCrossGrid');

// 不限制总行数
// 大列12   小列11
class CrossGrid{

    // 首行是否是 偶数行
    constructor(firstEven = true){
        this.bFirstEven = firstEven;
        if (firstEven){
            this.ref = evenCrossGrid;
        }else{
            this.ref = oddCrossGrid;
        }
    }

    step(lst,rowIdx,colIdx,block){
        lst.push([rowIdx,colIdx]);
        return block(rowIdx,colIdx);
    }

    getPosByRadius(rowIdx,colIdx,radius = 1){

        let ref = this.ref;

        // 可以分为6条边
        let tmpRowIndex = rowIdx;
        let tmpColIndex = colIdx - radius;
        let ret = [];

        // 左上边  /
        for(let i = 0; i < radius;++i){
            [tmpRowIndex,tmpColIndex] = this.step(ret,tmpRowIndex,tmpColIndex,ref.getRightUp);
        }

        // '-' 正上边
        for(let i = 0; i < radius; ++i){
            [tmpRowIndex,tmpColIndex] = this.step(ret,tmpRowIndex,tmpColIndex,ref.getRight);
        }

        // '\' 右上边
        for(let i = 0; i < radius; ++i){
            [tmpRowIndex,tmpColIndex] = this.step(ret,tmpRowIndex,tmpColIndex,ref.getRightDown);
        }

        //   '/'  这条边
        for (let i = 0; i < radius; ++i){
            [tmpRowIndex,tmpColIndex] = this.step(ret,tmpRowIndex,tmpColIndex,ref.getLeftDown);
        }

        // 正下边
        for (let i = 0; i < radius; ++i){
            [tmpRowIndex,tmpColIndex] = this.step(ret,tmpRowIndex,tmpColIndex,ref.getLeft);
        }

        // '\'  这条边
        for(let i = 0; i < radius; ++i){
            [tmpRowIndex,tmpColIndex] = this.step(ret,tmpRowIndex,tmpColIndex,ref.getLeftUp);
        }
        return ret;
    }

    // delegate
    getLeft(rowIdx,colIdx){
        return this.ref.getLeft(rowIdx,colIdx)
    }

    getRight(rowIdx,colIdx){
        return this.ref.getRight(rowIdx,colIdx);
    }

    getLeftUp(rowIdx,colIdx){
        return this.ref.getLeftUp(rowIdx,colIdx);
    }

    getLeftDown(rowIdx,colIdx){
        return this.ref.getLeftDown(rowIdx,colIdx);
    }

    getRightUp(rowIdx,colIdx){
        return this.ref.getRightUp(rowIdx,colIdx);
    }

    getRightDown(rowIdx,colIdx){
        return this.ref.getRightDown(rowIdx,colIdx);
    }

    getMaxColIdx(rowIdx){
        return this.ref.getMaxColIdx(rowIdx);
    }
}

module.exports = CrossGrid;
